import React from 'react';
import { Button, Tabs, Modal } from 'antd';
import { inject, observer } from 'mobx-react';
import { WeaRightMenu, WeaReqTop, WeaNewScroll, WeaSearchGroup, WeaBrowser, WeaFormItem, WeaDatePicker, WeaTimePicker, WeaTools, WeaAlertPage, WeaDraggable, WeaTop, WeaTab } from 'ecCom';
import { WeaTableNew, WeaSwitch } from 'comsMobx';

const WeaTable = WeaTableNew.WeaTable;
const getKey = WeaTools.getKey;
import { toJS } from 'mobx';
import ViewCustomerBase from './viewCustomerBase';
import CustomerBaseAboutDialog from '../dialog/customerBaseAboutDialog';
import CustomerContact from '../public/CustomerContact';
import OutResourceList from './OutResourceList';
import RemindSetModal from '../dialog/setRemindDialog';
import CustomerShare from './CustomerShare';
import ModifyRecord from '../log/ModifyRecord';
import CustomerEvaluation from './CustomerEvaluation';
import AddressManage from './AddressManage';
import CustomerMessage from '../public/CustomerMessage';
import ContractManage from '../ContractManage';
import SellChanceList from '../sellChance/List';
import ContacterMind from './contacterMap';
// import WorkPlan from "weaWorkplan"
// const WorkPlanCreate = WorkPlan.com.WorkPlanCreate;

import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

@inject('customerCardStore', 'contractManageStore', 'crmInfoRightmenuStore', 'chanceListStore')
@observer
export default class CustomerCard extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      visible: false,
      crmArr: [],
      visibleCowork: false,
      workplanLoaded: false,
      coworkLoaded: false,
    };
  }
  componentDidMount() {
    this.doInit();

    if (window.weaWorkplan) {
      this.setState({ workplanLoaded: true });
    } else {
      eventRegister.loadModule('f_workplan', () => {
        this.setState({ workplanLoaded: true });
      }, () => {
        // 加载文件失败 的业务处理， 网络超时，没文件之类
        alert('加载日程模块失败，请联系系统管理员！');
      });
    }

    if (window.weaCowork) {
      this.setState({ coworkLoaded: true });
    } else {
      eventRegister.loadModule('f_cowork', () => {
        this.setState({ coworkLoaded: true });
      }, () => {
        // 加载文件失败 的业务处理， 网络超时，没文件之类
        alert('加载协作模块失败，请联系系统管理员！');
      });
    }
  }

  doInit() {
    const { customerCardStore, location: { query }, crmInfoRightmenuStore } = this.props;
    const { initTabDatas, getFormCondition } = customerCardStore;
    initTabDatas(query);
    getFormCondition();
    crmInfoRightmenuStore.saveCustomerId(query);
    if (window.location.pathname.indexOf('/spa/crm/mobx/index') >= 0) {
      document.title = getLabel(367, '查看') + getLabel(20323, '客户信息');
    }
  }

  render() {
    const account = WeaTools.ls.getJSONObj('theme-account'); // 当前登陆人信息
    const { customerCardStore, location, crmInfoRightmenuStore } = this.props;
    const { title, tabDatas, detailTabKey, loading, hasRight, verified, crmInfoContactStore, customerId, crmOutResourceStore, remindInfo, addressManageStore, crmMessageStore, customerName,
    } = customerCardStore;
    toJS(this.props.customerCardStore.conditioninfo);
    if (verified && !hasRight) {
      return (<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@pu8np3`} >
        <div style={{ color: '#000' }}>
          {getLabel(2012, '对不起，您暂时没有权限！')}
        </div>
      </WeaAlertPage>
      );
    }
    const urlParams = location.query;
    if (verified && hasRight) {
      const tabDatas1 = toJS(tabDatas);
      const tabUrl = (function (key) {
        if (tabDatas1) {
          for (let i = 0; i < tabDatas1.length; i++) {
            if (tabDatas1[i].id == key && tabDatas1[i].shortname == 'baseinfo') { // 基本信息
              return [<ViewCustomerBase ecId={`${this && this.props && this.props.ecId || ''}_ViewCustomerBase@mlzsxx@${key}`} contentStore={customerCardStore} location={location} />, <CustomerBaseAboutDialog ecId={`${this && this.props && this.props.ecId || ''}_CustomerBaseAboutDialog@y2s87y@${key}`} contentStore={crmInfoRightmenuStore} />];
            } else if (tabDatas1[i].id == key && tabDatas1[i].shortname == 'outresourceinfo') { // 外部用户
              return <OutResourceList ecId={`${this && this.props && this.props.ecId || ''}_OutResourceList@5ears2`} contentStore={crmOutResourceStore} customerId={customerId} location={location} />;
            } else if (tabDatas1[i].id == key && tabDatas1[i].shortname == 'contactinfo') { // 客户联系
              return <CustomerContact ecId={`${this && this.props && this.props.ecId || ''}_CustomerContact@f3nlvv`} ref="contactlogs" contentStore={crmInfoContactStore} params={{ from: 'all', customerId }} location={location} />;
            } else if (tabDatas1[i].id == key && tabDatas1[i].shortname == 'loginfo') { // 修改记录
              return <ModifyRecord ecId={`${this && this.props && this.props.ecId || ''}_ModifyRecord@gfumql`} contentStore={customerCardStore} location={location} />;
            } else if (tabDatas1[i].id == key && tabDatas1[i].shortname == 'shareinfo') { // 共享设置
              return <CustomerShare ecId={`${this && this.props && this.props.ecId || ''}_CustomerShare@9ubfrj`} contentStore={customerCardStore} location={location} />;
            } else if (tabDatas1[i].id == key && tabDatas1[i].shortname == 'addressinfo') { // 地址管理
              return <AddressManage ecId={`${this && this.props && this.props.ecId || ''}_AddressManage@zrzj1s`} contentStore={addressManageStore} location={location} />;
            } else if (tabDatas1[i].id == key && tabDatas1[i].shortname == 'sellchanceinfo') { // 商机管理
              return <SellChanceList ecId={`${this && this.props && this.props.ecId || ''}_SellChanceList@gav2vu`} params={{ customerId }} />;
            } else if (tabDatas1[i].id == key && tabDatas1[i].shortname == 'contractinfo') { // 合同管理
              return <ContractManage ecId={`${this && this.props && this.props.ecId || ''}_ContractManage@mvc8a5`} location={location} />;
            } else if (tabDatas1[i].id == key && tabDatas1[i].shortname == 'evaluationinfo') { // 客户价值
              return <CustomerEvaluation ecId={`${this && this.props && this.props.ecId || ''}_CustomerEvaluation@jmt78q`} contentStore={customerCardStore} location={location} />;
            } else if (tabDatas1[i].id == key && tabDatas1[i].shortname == 'exchangeinfo') { // 客户留言
              return <CustomerMessage ecId={`${this && this.props && this.props.ecId || ''}_CustomerMessage@cy837h`} contentStore={crmMessageStore} location={location} />;
            } else if (tabDatas1[i].id == key && tabDatas1[i].shortname == 'contactermind') { // 联系人地图
              return <ContacterMind ecId={`${this && this.props && this.props.ecId || ''}_ContacterMind@zk30d6`} location={location} />;
            } else if (tabDatas1[i].id == key && (tabDatas1[i].shortname == '' || tabDatas1[i].shortname == 'enterpriseinfo')) {
              return tabDatas1[i].linkurl;
            }
          }
          return '';
        }
      }(detailTabKey));
      let WorkPlanCreate = {};
      if (window.weaWorkplan) {
        WorkPlanCreate = weaWorkplan.com.WorkPlanCreate;
      }
      const topHeight = 40;
      const tabHeight = 40;
      const tempHeight = topHeight + tabHeight;
      const contentHeight = 'calc(100% - 53px)';
      return (
        <div style={{ height: '100%' }}>
          <WeaRightMenu
            ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@1odz7c`}
            width={200}
            datas={this.getRightMenu()}
            onClick={this.onRightMenuClick.bind(this)}
            collectParams={{
              favname: getLabel(20323, '客户信息'),
              favouritetype: 4,
              importantlevel: 1,
              objid: -1,
            }}
          >
            <WeaTop
              ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@11onau`}
              title={customerName}
              loading={loading}
              icon={<i className="icon-coms-crm" />}
              iconBgcolor="#96358a"
              buttons={[]}
              buttonSpace={10}
              showDropIcon
              dropMenuDatas={this.getRightMenu()}
              onDropMenuClick={this.onRightMenuClick.bind(this)}
              buttons={this.getButtons()}
            >
              <WeaTab
                ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@8na3yd`}
                selectedKey={detailTabKey}
                keyParam="key" // 主键
                // countParam="groupid" //数量
                type="editable-inline"
                onChange={this.crmCardChangeTab.bind(this)}
                datas={tabDatas.slice()}
                onEdit={customerCardStore.onTabEdit}
              />
              <div style={{ height: contentHeight }}>
                {/* <WeaNewScroll scrollId='crm-req-content-main-scroll' height='100%'> */}
                {
                  typeof tabUrl === 'object' ? tabUrl :
                    <iframe src={tabUrl} id="crmtabiframe" name="crmtabiframe" className="flowFrame" frameBorder="0" width="100%" height="100%" />
                }
                {/* </WeaNewScroll> */}
              </div>
            </WeaTop>
            <RemindSetModal ecId={`${this && this.props && this.props.ecId || ''}_RemindSetModal@cww3py`} ref="remindSetInCustomerCard" remindInfo={toJS(remindInfo)} customerId={customerId} saveRemindSetting={this.saveRemindSetting} />
          </WeaRightMenu>
          {window.weaWorkplan && this.state.workplanLoaded && (
            <WorkPlanCreate
              ecId={`${this && this.props && this.props.ecId || ''}_WorkPlanCreate@wjx9mi`}
              type={'create'}// 新建为'create',查看为'preview',编辑edit,共享share
              visible={this.state.visible}// 显隐受控
              doClose={() => { this.setWorkPlanVisisble(false); }}// 关闭回调
              onlyClose={() => { this.setWorkPlanVisisble(false); }}// 关闭回调,只做关闭操作
              workPlanId={''} // 日程id，1查看日程时用到
              createConditionParams={[]}// 创建的默认值日期和时间,没有传[]
              activeKey={''} // 查看页面显示的面板1是基本信息，7是相关交流
              changeTab={() => {}}// 查看页面切换面板的回调
              selectUser={account && account.userid}// 新建日程的创建人id
              workPlanTypeOptions={3}// 客户模块的新建日程，普通新建传'',客户新建传3
              crmIDs={this.state.visible && this.state.crmArr}// 通过客户模块新建日程，并自动带出相关客户,[{'id':'','name':''}]
              description={this.state.value}
            />
          )}
          {window.weaCowork && window.weaCowork.com && window.weaCowork.com.CreateCowork && this.state.visibleCowork && this.state.coworkLoaded && (
            <window.weaCowork.com.CreateCowork
              ecId={`${this && this.props && this.props.ecId || ''}_undefined@q9q0kr`}
              random={Math.random()}
              initAddQuery={
                {
                  relatedType: 'crm',
                  ids: customerId,
                }
              }
              onCancel={() => {
                this.setState({ visibleCowork: false });
              }}
            />)
          }


        </div>
      );
    }
    return (<div />);
  }
  getButtons() {
    const { customerCardStore, contractManageStore, location } = this.props;
    const { rightMenu, customerId, form, detailTabKey, taskInfoStore, tabDatas, crmOutResourceStore, shareTableStore, shareStore, addressManageStore, rightLevel, currentPageState, modifyTableStore } = customerCardStore;
    const btnArr = [];
    const that = this;
    toJS(tabDatas).map((item) => {
      if (item.key == detailTabKey && item.shortname == 'contactinfo') { // 客户联系
        btnArr.push((<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@dpe1wa@contactRemindSet`} type="primary" onClick={this.setContactRemind.bind(this)}>{getLabel(84369, '联系提醒设置')}</Button>));
      } else if (item.key == detailTabKey && item.shortname == 'outresourceinfo') {
        const { rightMenu, tableStore, deleteOutResource, outResourceAdd, showAddForm, saveOutResourceForm } = crmOutResourceStore;
        const { selectedRowKeys } = tableStore;
        const isDisabled = !(selectedRowKeys.length > 0 && `${toJS(selectedRowKeys)}`);
        { !showAddForm && rightMenu && rightMenu.length > 0 && rightMenu.map((m) => {
          m.isTop == '1' && btnArr.length < 4 && btnArr.push(
            <Button
              ecId={`${this && this.props && this.props.ecId || ''}_Button@6hfvdi@${m.type}`}
              type="primary"
              disabled={isDisabled && m.isControl == '1'}
              onClick={() => {
                if (m.type == 'BTN_CREATE') { // 新建
                  outResourceAdd({ customerId });
                } else if (m.type == 'BTN_DELETEBATCH') { // 删除
                  deleteOutResource({ operation: 'delete', id: `${toJS(selectedRowKeys)}` }, customerId);
                }
              }}
            >
              {m.menuName}
            </Button>,
          );
        });
        }
        {
          showAddForm &&
                    btnArr.push(
                      <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@y8gq43@save`} type="primary" onClick={() => { saveOutResourceForm({ operation: 'add', customerId }); }}>
                        {getLabel(86, '保存')}
                      </Button>);
        }
      } else if (item.key == detailTabKey && item.shortname == 'shareinfo') { // 共享设置
        const { selectedRowKeys } = shareTableStore;
        const isDisabled = !(selectedRowKeys.length > 0 && `${toJS(selectedRowKeys)}`);
        rightMenu.map((m) => {
          m.isTop == '1' && btnArr.length < 4 && btnArr.push(
            <Button
              ecId={`${this && this.props && this.props.ecId || ''}_Button@svfqjq@${m.type}`}
              type="primary"
              disabled={isDisabled && m.isControl == '1'}
              onClick={() => {
                if (m.type == 'BTN_APPEND') {
                  shareStore.handleShareDialog(true);
                } else if (m.type == 'BTN_DELETEBATCH') { // 删除
                  customerCardStore.shareSettingDelete({ id: `${toJS(selectedRowKeys)}` }, customerId);
                }
              }}
            >
              {m.menuName}
            </Button>,
          );
        });
      } else if (item.key == detailTabKey && item.shortname == 'loginfo') { // 操作日志
        rightMenu.map((m) => {
          m.isTop == '1' && btnArr.length < 4 && btnArr.push(
            <Button
              ecId={`${this && this.props && this.props.ecId || ''}_Button@60hib1@${m.type}`}
              type="primary"
              onClick={() => {
                if (m.type == 'BTN_EXPORT') {
                  // shareStore.handleShareDialog(true);

                  modifyTableStore.exportAll();
                }
              }}
            >
              {m.menuName}
            </Button>,
          );
        });
      } else if (item.key == detailTabKey && item.shortname == 'evaluationinfo') { // 客户价值
        rightMenu.map((m) => {
          m.isTop == '1' && btnArr.length < 4 && btnArr.push(
            <Button
              ecId={`${this && this.props && this.props.ecId || ''}_Button@7fqogv@${m.type}`}
              type="primary"
              onClick={() => {
                if (m.type == 'BTN_UPDATE') {
                  this.updateCustomerEval();
                }
              }}
            >
              {m.menuName}
            </Button>,
          );
        });
      } else if (item.key == detailTabKey && item.shortname == 'addressinfo') { // 地址管理
        const { tableStore, rightMenu, customerId } = addressManageStore;
        const { selectedRowKeys } = tableStore;
        const isDisabled = !(selectedRowKeys.length > 0 && `${toJS(selectedRowKeys)}`);
        rightMenu.map((m) => {
          m.isTop == '1' && btnArr.length < 4 && btnArr.push(
            <Button
              ecId={`${this && this.props && this.props.ecId || ''}_Button@2gv4ne@${m.type}`}
              type="primary"
              disabled={isDisabled && m.isControl == '1'}
              onClick={() => {
                if (m.type == 'BTN_CREATE') {
                  addressManageStore.operateAddressForm(true, { customerId }, 'add');
                } else if (m.type == 'BTN_DELETEBATCH') { // 删除
                  addressManageStore.deleteAddress({ ids: `${toJS(selectedRowKeys)}` });
                }
              }}
            >
              {m.menuName}
            </Button>,
          );
        });
      } else if (item.key == detailTabKey && item.shortname == 'contractinfo') { // 合同管理
        const { rightMenu, tableStore, getContractInfo, deleteContractBatch } = contractManageStore;
        const { selectedRowKeys } = tableStore;
        const isDisabled = !(toJS(selectedRowKeys) && toJS(selectedRowKeys).length > 0 && `${toJS(selectedRowKeys)}`);
        rightMenu.map((m) => {
          m.isTop == '1' && btnArr.length < 4 && btnArr.push(
            <Button
              ecId={`${this && this.props && this.props.ecId || ''}_Button@wgereq@${m.type}`}
              type="primary"
              disabled={isDisabled && m.isControl == '1'}
              onClick={() => {
                if (m.type == 'BTN_CREATE') {
                  getContractInfo({ operation: 'add', crmId: location.query.customerId }, '1', false);
                } else if (m.type == 'BTN_DELETEBATCH') {
                  deleteContractBatch(`${toJS(selectedRowKeys)}`);
                }
              }}
            >
              {m.menuName}
            </Button>,
          );
        });
      } else if (item.key == detailTabKey && item.shortname == 'sellchanceinfo') { // 商机管理
        const { chanceListStore } = this.props;
        const { selectedRowKeys } = chanceListStore.tableStore;
        const isDisabled = !(toJS(selectedRowKeys) && toJS(selectedRowKeys).length > 0 && `${toJS(selectedRowKeys)}`);
        chanceListStore.rightMenu.map((m) => {
          m.isTop == '1' && btnArr.length < 4 && btnArr.push(
            <Button
              ecId={`${this && this.props && this.props.ecId || ''}_Button@eaa97k@${m.type}`}
              type="primary"
              disabled={isDisabled && m.isControl == '1'}
              onClick={() => {
                if (m.type == 'BTN_CREATE') {
                  const params = {};
                  params.operation = 'add';
                  params.customerid = customerId;
                  chanceListStore.showChanceDialog(true, params, getLabel(82, '新建') + getLabel(32922, '商机'));
                } else if (m.type == 'BTN_DELETEBATCH') {
                  Modal.confirm({
                    title: getLabel(15172, '系统提示'),
                    content: getLabel(83600, '您确认要删除吗？'),
                    okText: getLabel(33703, '确定'),
                    cancelText: getLabel(201, '取消'),
                    onOk() {
                      chanceListStore.batchDelete(`${toJS(selectedRowKeys)}`);
                    },
                  });
                }
              }}
            >
              {m.menuName}
            </Button>,
          );
        });
      } else if (item.key == detailTabKey && item.shortname == 'baseinfo' && rightLevel > 1) { // 基本信息
        let btnName = getLabel(93, '编辑');
        if (currentPageState == 'edit') {
          btnName = getLabel(1290, '返回');
        }
        btnArr.push(
          <Button
            ecId={`${this && this.props && this.props.ecId || ''}_Button@n3592z@edit`}
            type="primary"
            onClick={() => {
              customerCardStore.editHandle();
            }}
          >
            {btnName}
          </Button>,
        );
      }
    });
    return btnArr;
  }
  getRightMenu() {
    const { customerCardStore, contractManageStore, crmInfoRightmenuStore } = this.props;
    const { rightMenu, detailTabKey, tabDatas, crmOutResourceStore, shareTableStore, addressManageStore } = customerCardStore;
    const btns = [];
    tabDatas.toJS().map((item) => {
      if (item.key == detailTabKey && item.shortname == 'baseinfo') { // 基本信息
        toJS(rightMenu).map((item) => {
          if (item.key) {
            let _icon = 'icon-coms-Need-feedback';
            let _store = 'crmInfoRightmenuStore.';
            if (item.key == '2') { // 导出客户联系
              _icon = 'icon-coms-export ';
            } else if (item.key == '3') { // 新建邮件
              _icon = 'icon-coms-Send-emails';
            } else if (item.key == '39') { // 新建工作流
              _icon = 'icon-coms-Workflow';
            } else if (item.key == '40') { // 新建协作事件
              _icon = 'icon-coms-synergism ';
            } else if (item.key == '41') { // 新建计划
              _icon = 'icon-coms-Planning-tasks';
            } else if (item.key == '42') { // 客户合并
              _icon = 'icon-coms-HumanResources';
            } else if (item.key == '4') { // 删除
              _icon = 'icon-coms-delete';
            } else if (item.key.indexOf('extend') != -1) {
              _icon = 'icon-coms-link';
              _store = 'customerCardStore.';
            } else if (item.key == '50') { // 分享
              _icon = 'icon-coms-Batch-sharing';
            }
            return btns.push({
              icon: <i className={_icon} />,
              content: `${item.content}`,
              key: `${item.key}`,
              onClick: (key) => { eval(`${_store}${item.fn}`); },
            });
          }
        });
      } else if (item.key == detailTabKey && item.shortname == 'outresourceinfo') { // 外部用户
        const { rightMenu, tableStore, showAddForm } = crmOutResourceStore;
        const { selectedRowKeys } = tableStore;
        const isDisabled = !(selectedRowKeys.length > 0 && `${toJS(selectedRowKeys)}`);
        {
          !showAddForm && rightMenu && rightMenu.length > 0 && rightMenu.map((m) => {
            btns.push({
              icon: <i className={m.menuIcon} />,
              content: m.menuName,
              disabled: isDisabled && m.isControl == '1',
            });
          });
        }
        { showAddForm &&
                    btns.push({
                      icon: <i className="icon-coms-Preservation " />,
                      content: getLabel(86, '保存'),
                      key: 3,
                    });
        showAddForm &&
                     btns.push({
                       icon: <i className="icon-coms-Return " />,
                       content: getLabel(1290, '返回'),
                       key: 4,
                     });
        }
      } else if (item.key == detailTabKey && item.shortname == 'shareinfo') { // 共享设置
        const { selectedRowKeys } = shareTableStore;
        const isDisabled = !(selectedRowKeys.length > 0 && `${toJS(selectedRowKeys)}`);
        rightMenu && rightMenu.length > 0 && rightMenu.map((m) => {
          btns.push({
            icon: <i className={m.menuIcon} />,
            content: m.menuName,
            disabled: isDisabled && m.isControl == '1',
          });
        });
      } else if (item.key == detailTabKey && item.shortname == 'loginfo') { // 修改记录
        rightMenu && rightMenu.length > 0 && rightMenu.map((m) => {
          btns.push({
            icon: <i className={m.menuIcon} />,
            content: m.menuName,
          });
        });
      } else if (item.key == detailTabKey && item.shortname == 'evaluationinfo') { // 客户价值
        rightMenu && rightMenu.length > 0 && rightMenu.map((m) => {
          btns.push({
            icon: <i className={m.menuIcon} />,
            content: m.menuName,
          });
        });
      } else if (item.key == detailTabKey && item.shortname == 'addressinfo') { // 地址管理
        const { tableStore, rightMenu } = addressManageStore;
        const { selectedRowKeys } = tableStore;
        const isDisabled = !(selectedRowKeys.length > 0 && `${toJS(selectedRowKeys)}`);
        rightMenu && rightMenu.length > 0 && rightMenu.map((m) => {
          btns.push({
            icon: <i className={m.menuIcon} />,
            content: m.menuName,
            disabled: isDisabled && m.isControl == '1',
          });
        });
      } else if (item.key == detailTabKey && item.shortname == 'contractinfo') { // 合同管理
        const { rightMenu, tableStore } = contractManageStore;
        const { selectedRowKeys } = tableStore;
        const isDisabled = !(toJS(selectedRowKeys) && toJS(selectedRowKeys).length > 0 && `${toJS(selectedRowKeys)}`);
        rightMenu.map((m) => {
          btns.push({
            icon: <i className={m.menuIcon} />,
            content: m.menuName,
            disabled: isDisabled && m.isControl == '1',
          });
        });
      } else if (item.key == detailTabKey && item.shortname == 'sellchanceinfo') { // 商机管理
        const { chanceListStore } = this.props;
        const { selectedRowKeys } = chanceListStore.tableStore;
        const isDisabled = !(toJS(selectedRowKeys) && toJS(selectedRowKeys).length > 0 && `${toJS(selectedRowKeys)}`);
        chanceListStore.rightMenu.map((m) => {
          btns.push({
            icon: <i className={m.menuIcon} />,
            content: m.menuName,
            disabled: isDisabled && m.isControl == '1',
          });
        });
      }
    });
    	return btns;
  }
    setWorkPlanVisisble=(bool) => {
      this.setState({ visible: bool });
    }
    getCustomerInfo=(customerId) => {
      const crmArr = [];
      WeaTools.callApi('/api/crm/customer/getCrmNamesById', 'GET', { customerIds: customerId }).then((data) => {
        if (data.status == 'success') {
          crmArr.push({ id: customerId, name: data.datas });
          this.setState({ visible: true, crmArr });
        }
      });
      // return crmArr;
    }
    onRightMenuClick(key) {
      const that = this;
      const { customerCardStore, contractManageStore, location, crmInfoRightmenuStore } = this.props;
      const { rightMenu, detailTabKey, customerId, addProjectStore, tabDatas, crmOutResourceStore, shareTableStore, shareStore,
        modifyTableStore, addressManageStore, customerName,
      } = customerCardStore;
      tabDatas.toJS().map((item) => {
        if (item.key == detailTabKey && item.shortname == 'baseinfo') { // 基本信息
          if (key == '2') { // 导出客户联系
            crmInfoRightmenuStore.contactLogExport(customerId);
          } else if (key == '3') { // 新建邮件
            crmInfoRightmenuStore.addMailMenu(customerId);
          } else if (key == '39') { // 新建工作流
            crmInfoRightmenuStore.addWorkflow(customerId);
          } else if (key == '40') { // 新建协作事件
            that.setState({ visibleCowork: true });
            // crmInfoRightmenuStore.addCowork(customerId);
            const coworkStoreMap = window.weaCowork.store && window.weaCowork.store.coworkStoreMap;
            const cowortore = coworkStoreMap && coworkStoreMap.getMapStore(3);
            cowortore && cowortore.setCreateState({ showNewCowork: true, createOrEdit: 0 });
          } else if (key == '41') { // 新建计划
            this.getCustomerInfo(customerId);
          } else if (key == '44') { // 客户合并
            const modalInfo = {
              modalTitle: getLabel(84367, '客户合并'),
              modalStyle: { width: 446, height: 180 },
              modalType: 'customerMerge',
            };
            crmInfoRightmenuStore.getUniteForm(customerId);
            crmInfoRightmenuStore.showDilog(true, modalInfo);
          } else if (key == '45') { // 修改密码
            const modalInfo = {
              modalTitle: getLabel(125283, '设置密码'),
              modalStyle: { width: 446, height: 180 },
              modalType: 'setPasswd',
            };
            crmInfoRightmenuStore.showDilog(true, modalInfo);
          } else if (key == '4') { // 删除
            Modal.confirm({
              title: getLabel(15172, '系统提示'),
              content: getLabel(83600, '您确认要删除吗？'),
              okText: getLabel(33703, '确定'),
              cancelText: getLabel(201, '取消'),
              onOk() {
                crmInfoRightmenuStore.deleteCustomer(customerId);
              },
              onCancel() {},
            });
          } else if (key == '46') { // 工商信息
            crmInfoRightmenuStore.getBusinessInfo(customerId);
          } else if (key == '201') { // 客户状态变更
            const modalInfo = {
              modalTitle: getLabel(15157, '客户状态变更'),
              modalStyle: { width: 446, height: 180 },
              modalType: 'statusChange',
            };
            crmInfoRightmenuStore.getStatusChangeForm(customerId);
            crmInfoRightmenuStore.showDilog(true, modalInfo);
          } else if (key == '50') { // 分享
            crmInfoRightmenuStore.showShareDilog(true);
          }
        } else if (item.key == detailTabKey && item.shortname == 'outresourceinfo') { // 外部用户
          const { rightMenu, tableStore, deleteOutResource, showAddForm, outResourceAdd, goback, saveOutResourceForm } = crmOutResourceStore;
          const { selectedRowKeys } = tableStore;
          {
            !showAddForm && rightMenu && rightMenu.length > 0 && rightMenu.map((m, i) => {
              if (Number(key) == i) {
                if (m.type == 'BTN_CREATE') { // 新建
                  outResourceAdd({ customerId });
                } else if (m.type == 'BTN_COLUMN') { // 定制列
                  tableStore.setColSetVisible(true);
                  tableStore.tableColSet(true);
                } else if (m.type == 'BTN_DELETEBATCH') { // 删除
                  deleteOutResource({ operation: 'delete', id: `${toJS(selectedRowKeys)}` }, customerId);
                }
              }
            });
          }
          {
            showAddForm && key == '3' && saveOutResourceForm({ operation: 'add', customerId }); // 新建保存
          }
          {
            showAddForm && key == '4' && goback(); // 新建 返回
          }
        } else if (item.key == detailTabKey && item.shortname == 'shareinfo') { // 共享设置
          const { selectedRowKeys } = shareTableStore;
          const isDisabled = !(selectedRowKeys.length > 0 && `${toJS(selectedRowKeys)}`);
          rightMenu.map((m, i) => {
            if (Number(key) == i) {
              if (m.type == 'BTN_APPEND') {
                shareStore.handleShareDialog(true);
              } else if (m.type == 'BTN_DELETEBATCH') { // 删除
                customerCardStore.shareSettingDelete({ id: `${toJS(selectedRowKeys)}` }, customerId);
              } else if (m.type == 'BTN_COLUMN') {
                shareTableStore.setColSetVisible(true);
                shareTableStore.tableColSet(true);
              }
            }
          });
        } else if (item.key == detailTabKey && item.shortname == 'loginfo') { // 修改记录
          rightMenu.map((m, i) => {
            if (Number(key) == i) {
              if (m.type == 'BTN_EXPORT') {
                modifyTableStore.exportAll();
              }
            }
          });
        } else if (item.key == detailTabKey && item.shortname == 'evaluationinfo') { // 客户价值
          rightMenu && rightMenu.length > 0 && rightMenu.map((m, i) => {
            if (Number(key) == i) {
              if (m.type == 'BTN_UPDATE') {
                this.updateCustomerEval();
              }
            }
          });
        } else if (item.key == detailTabKey && item.shortname == 'addressinfo') { // 地址管理
          const { tableStore, rightMenu, customerId } = addressManageStore;
          const { selectedRowKeys } = tableStore;
          const isDisabled = !(selectedRowKeys.length > 0 && `${toJS(selectedRowKeys)}`);
          rightMenu.map((m, i) => {
            if (Number(key) == i) {
              if (m.type == 'BTN_CREATE') {
                addressManageStore.operateAddressForm(true, { customerId }, 'add');
              } else if (m.type == 'BTN_DELETEBATCH') { // 删除
                addressManageStore.deleteAddress({ ids: `${toJS(selectedRowKeys)}` });
              } else if (m.type == 'BTN_COLUMN') {
                tableStore.setColSetVisible(true);
                tableStore.tableColSet(true);
              }
            }
          });
        } else if (item.key == detailTabKey && item.shortname == 'contractinfo') { // 合同管理
          const { rightMenu, tableStore, getContractInfo, deleteContractBatch } = contractManageStore;
          const { selectedRowKeys } = tableStore;
          const isDisabled = !(toJS(selectedRowKeys) && toJS(selectedRowKeys).length > 0 && `${toJS(selectedRowKeys)}`);
          rightMenu.map((m, i) => {
            if (Number(key) == i) {
              if (m.type == 'BTN_CREATE') {
                getContractInfo({ operation: 'add', crmId: location.query.customerId }, '1', false);
              } else if (m.type == 'BTN_COLUMN') {
                tableStore.setColSetVisible(true);
                tableStore.tableColSet(true);
              } else if (m.type == 'BTN_DELETEBATCH') {
                deleteContractBatch(`${toJS(selectedRowKeys)}`);
              }
            }
          });
        } else if (item.key == detailTabKey && item.shortname == 'sellchanceinfo') {
          const { chanceListStore } = this.props;
          const { selectedRowKeys } = chanceListStore.tableStore;
          const isDisabled = !(toJS(selectedRowKeys) && toJS(selectedRowKeys).length > 0 && `${toJS(selectedRowKeys)}`);
          chanceListStore.rightMenu.map((m, i) => {
            if (Number(key) == i) {
              if (m.type == 'BTN_CREATE') {
                const params = {};
                params.operation = 'add';
                params.customerid = customerId;
                chanceListStore.showChanceDialog(true, params, getLabel(82, '新建') + getLabel(32922, '商机'));
              } else if (m.type == 'BTN_COLUMN') {
                chanceListStore.tableStore.setColSetVisible(true);
                chanceListStore.tableStore.tableColSet(true);
              } else if (m.type == 'BTN_SEARCH') {
                chanceListStore.doSearch();
              } else if (m.type == 'BTN_DELETEBATCH') {
                Modal.confirm({
                  title: getLabel(15172, '系统提示'),
                  content: getLabel(83600, '您确认要删除吗？'),
                  okText: getLabel(33703, '确定'),
                  cancelText: getLabel(201, '取消'),
                  onOk() {
                    chanceListStore.batchDelete(`${toJS(selectedRowKeys)}`);
                  },
                });
              }
            }
          });
        }
      });
    }
    crmCardChangeTab(key) {
      const { customerCardStore } = this.props;
      customerCardStore.changeTab(key);
    }

    setContactRemind() {
      const { customerId, getRemindInfo } = this.props.customerCardStore;
      getRemindInfo(customerId);
      this.refs.remindSetInCustomerCard.setContactVisible(true);
    }
    saveRemindSetting = (params = {}) => {
      const { saveContactRemind } = this.props.customerCardStore;
      saveContactRemind(params);
    }
    updateCustomerEval=() => {
      const { evalStandard, evalDataSources, evalParams, evaluationUpdate, customerId } = this.props.customerCardStore;
      let params = toJS(evalParams);
      if (JSON.stringify(params) == '{}') {
        const _dataSource = [].concat(toJS(evalDataSources));
        const evalStandardArr = toJS(evalStandard);
        const levelArr = [];
        const proportionArr = [];
        const evaluationIDArr = [];
        for (let j = 0; j < _dataSource.length; j++) {
          levelArr.push(_dataSource[j].levelId || evalStandardArr[0].levelId);
          proportionArr.push(_dataSource[j].proportion);
          evaluationIDArr.push(_dataSource[j].id);
        }
        params = {
          level: `${levelArr}`,
          proportion: `${proportionArr}`,
          evaluationID: `${evaluationIDArr}`,
        };
      }
      evaluationUpdate({ customerId, ...params });
    }
}
